<template>
  <div class="category">
    <van-search
      shape="round"
      @focus="$router.push('/search')"
      placeholder="搜索商品"
    ></van-search>

    <van-tabs class="categorys" scrollspy sticky>
      <van-tab
        v-for="(cate, index) in categorys"
        :title="cate.cate_name"
        :key="index"
      >
        <div class="top_cate">
          <h2>
            <span>{{ cate.cate_name }}</span>
          </h2>
          <ul class="child_cate">
            <li v-for="(c, i) in cate.children" :key="i">
              <router-link :to="`${'/categorylist'}/${c.id}`">
                <img :src="c.pic" />
              </router-link>
              <h3>{{ c.cate_name }}</h3>
            </li>
          </ul>
        </div>
      </van-tab>
    </van-tabs>
  </div>
</template>
<script>
export default {
  data() {
    return {
      categorys: [],
    };
  },
  created() {
    this.axios.get("/category").then((result) => {
      this.categorys = result;
      console.log(result);
    });
  },
};
</script>
<style lang="less">
.category {
  .van-tabs__nav--line.van-tabs__nav--complete {
    padding-left: 0px;
    padding-right: 0px;
    background: #f7f7f7;
  }
  .van-tabs__line {
    background-color: transparent;
  }
  .van-tab--active {
    color: red;
    border-left: 3px solid red;
    background: #fff;
  }
  .van-tabs__nav {
    height: 75.5vh;
    padding-bottom: 50px;
  }
  .van-tab .van-tab--active {
    color: red;
    border-left: 3px solid red;
    background: #fff;
  }
  .van-search {
    position: sticky;
    top: 0px;
    z-index: 4;
  }
  .van-tab__pane {
    padding-top: 10px;
  }
  .van-tabs__content {
    padding-left: 90px;
    padding-bottom: 55px;
    margin-top: -45px;
  }
  .van-tabs__nav {
    display: block;
    position: fixed;
    left: 0px;
    top: 53.98px;
  }
  .van-tabs__wrap--scrollable .van-tab {
    width: 90px;
    line-height: 40px;
  }
  .categorys {
    .top_cate {
      h2 {
        position: relative;
        height: 45px;
        line-height: 45px;
        text-align: center;
        span {
          font-size: 14px;
          font-weight: bold;
          position: absolute;
          left: 50%;
          top: 50%;
          z-index: 2;
          transform: translate(-50%, -50%);
          background-color: #ffffff;
          padding: 0px 15px;
        }
        &::before {
          content: "";
          width: 65%;
          border-top: 1px solid#333;
          position: absolute;
          left: 50%;
          top: 50%;
          z-index: 1;
          transform: translate(-50%, -50%);
        }
      }
      .child_cate {
        display: flex;
        flex-wrap: wrap;
        li {
          margin-top: 13px;
          text-align: center;
          flex: 33%;
          img {
            height: 60px;
            width: 60px;
            border-radius: 50%;
          }
          h3 {
            font-size: 12px;
          }
        }
      }
    }
  }
}
</style>